# Flores, Alejandro and Alexander Coppock
# Do Bilinguals Respond More Favorably to Candidate Advertisements in English or in Spanish?
# Forthcoming, Political Communication

rm(list = ls())

# Set your working directory to the replication archive directory

# Install software if necessary
# install.packages("tidyverse")

library(tidyverse)

study_1 <- read_csv("study_1.csv")
study_2 <- read_csv("study_2.csv")
study_3 <- read_csv("study_3.csv")

tab_1 <- with(filter(study_1, bilingual == 1), table(Z_survey, Z_ad))
tab_2 <- with(filter(study_2, bilingual == 1), table(Z_survey, Z_vela))
tab_3 <- with(filter(study_3, bilingual == 0), table(Z_vela))
tab_4 <- with(filter(study_2, bilingual == 1), table(Z_survey, Z_coffman))
tab_5 <- with(filter(study_3, bilingual == 0), table(Z_coffman))

table_3 <- rbind(tab_1, tab_2, tab_3, tab_4, tab_5)
table_3

chisq.test(table_3)

# Covariates

study_3 %>%
  summarise(age = mean(age, na.rm = TRUE),
            female = mean(female, na.rm = TRUE),
            hispanic = mean(hispanic, na.rm = TRUE),
            ethnicity = mean(ethnicity, na.rm = TRUE),
            HHI = mean(HHI, na.rm = TRUE))
